﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.IO;
using System.Windows.Forms;
using System.Threading;

namespace TestMySqlConnetPoll
{
    public struct NowObjValue
    {
        public ObjValue value { get; set; }  //当前值
        public string CXBZ { get; set; }     //超限标志，超上限 = “上限”，超下限 = “下限”，不超限= “”；
    }
    public struct objCodeDev       //模拟量类型+设备
    {
        public byte codetype;   //模拟量类型
        public Int16 dev_no;    //模拟量设备编号

        public override bool Equals(object obj)
        {
            if (this.codetype == ((objCodeDev)obj).codetype && this.dev_no == ((objCodeDev)obj).dev_no)
                return true;
            else
                return false;
        }
    }
    public struct objTV
    {
        public int utime;       //模拟量时间
        public Int16 value;     //模拟量转换成WORD类型的值
    }
    public struct ObjValue
    {
        public int DecimalNum;
        public float Value;     //直接返回浮点数
        public string ValueType;   //返回值的类型
    }

    public struct objTimeValue    //时间和值的基本结构
    {
        public int u_time;
        public Int16 Dvalue;   //网络和数据库中的值
        public ObjValue Tvalue;    //转换过后的值
    }

    public class ObjRealTimeValue
    {
        public string DevName = "";  //设备名称
        public List<ObjValue> DevValue = new List<ObjValue>();
    }

    public class objRealCurveGybdcqx    //实时高压不对称值
    {
        public string DevName = "";
        public DateTime time = new DateTime();
        public int DotNum = 0;
        public List<float> dValue = new List<float>();
    }
    [Serializable]
    public class objSendAlarmData
    {
        public DateTime sendtime;
        public ObjAlaram alarm = new ObjAlaram();
    }

    public class MessageInfoEventArgs : EventArgs
    {
        public MessageInfoEventArgs(string ErrorString)
        {
            this.ErrorString = ErrorString;
        }
        public string ErrorString { get; private set; }
    }

    public class kglstruct
    {
        public int adNumber { get; set; }     //开关量序号
        public string kglName {get;set;}     //名称
        public string type {get;set;}        //类型
        public string statue { get; set; }      //状态
        public string fjNo { get; set; }        //分机号
        public string MsgName { get; set; }     //设备类型
        public string DevName { get; set; }    //所属设备
        public string BHflag { get; set; }     //变化标志
    }

    static public class c_RealTimeValue     //实时值类
    {        
        static public event EventHandler<MessageInfoEventArgs> MessageInfo;
        /// <summary>
        /// 定义实时值变量，以设备类型做为键值，所有的实时值都放在该变量中。
        /// </summary>
        static public Dictionary<string, List<ObjRealTimeValue>> RealTimeValue_Analog = new Dictionary<string, List<ObjRealTimeValue>>();  //显示层实际用的值

        //static public DataTable KglRealTimeTable = new DataTable("开关量实时值");         //显示层实际用的开关量实时值表格
        static public List<kglstruct> kglRealTimeList = new List<kglstruct>();

        static public objRevKGL ReceiveKGLData = new objRevKGL();     //从外部接口获得的开关量原始值，站场图，状态图用的数据

        static public objRevKGL ReceiveChangeKglData = new objRevKGL(); //从外部接口获得的变化开关量，只存储最新的一次，每次收到变化开关量后都更新全体开关量

        static public DataTable JyRealTimeTable = new DataTable("电缆绝缘测试值");        //显示层用的绝缘实时值表格

        static public DataTable LlRealTimeTable = new DataTable("电源漏流测试值");         //显示层用的漏流实时值表格

        static public DataTable StatueTable = new DataTable("系统实时状态");

        //static public DataTable CyRealTimeTable = new DataTable("轨道分路残压值");         //显示层用的残压实时值表格，不做表格，不能全部显示，只能显示设置了残压的
        /// <summary>
        /// 接收到的报警，以等级做键值
        /// </summary>
        //static public Dictionary<byte, List<ObjAlaram>> ReceiveAlarmData = new Dictionary<byte,List<ObjAlaram>>();         //获得的报警数据，显示层用的数据
        //static public int AllRealTimeAlarmNum = 0;
        /// <summary>
        /// 接收到的高压不对称曲线，以设备号做键值.
        /// </summary>
        static public Dictionary<string, ObjGybdcType> RevRealTimeGYBDCqx = new Dictionary<string, ObjGybdcType>();
                

        //static public objRealCurveGybdcqx GybdcqxRealValue = new objRealCurveGybdcqx();

        static public Dictionary<objCodeDev, objTV> JyLlCyRealTimeValue = new Dictionary<objCodeDev,objTV>();  //绝缘漏流残压实时值

        //列控实时表格数据
        //public Dictionary<objLkKey, objLKHostHardTable> HostHardwarePlatform = new Dictionary<objLkKey, objLKHostHardTable>();

        static public DataTable HostHardwarePlatform = new DataTable("列控中心主机硬件平台");
        static public DataTable LianSuoJieKouRouteInfo = new DataTable("列控中心与联锁接口进路信息");
        static public DataTable LianSuoGaiFangCommandInfo = new DataTable("列控中心与联锁改方命令信息");
        static public DataTable LianSuoGaiFangCommandRet = new DataTable("列控中心与联锁改方回执信息");
        static public DataTable ZhanJianGaiFangCommandInfo = new DataTable("列控中心站间改方命令信息");
        static public DataTable ZhanJianGaiFangCommandRet = new DataTable("列控中心站间改方回执信息");
        static public DataTable ZhanJianBoundaryInfo = new DataTable("列控中心站间边界信息");
        static public DataTable SendToLianSuoInfo = new DataTable("发送给联锁的无配线站区间方向口信息");
        static public DataTable TemporaryLimitSpeedState = new DataTable("列控中心临时限速状态");
        static public DataTable SectionEncodeInfo = new DataTable("轨道区段编码信息");
        static public DataTable TransponderEncodeInfo = new DataTable("应答器报文编码信息");
        static public DataSet Statue_Info = new DataSet("全体状态信息");

        //以下为本类用的存储数据用的变量
        static public Dictionary<byte, List<Int16>> ReceiveAnalogData = new Dictionary<byte, List<short>>();        //从外部接口得到的原始数据

        static private List<objRevCommandType> ReceiveCommandData = new List<objRevCommandType>();

        static private JyLlCyTable JyLlobject = new JyLlCyTable();

        static private List<objRevLkType> ReceiveLkData = new List<objRevLkType>(); 

        /// <summary>
        /// 外部函数，初始化实时值表
        /// </summary>
        static public void InitRealTimeData()
        {
            InitKglRealTimeTable();             //初始化开关量实时值表
            InitMsgGatherRealTimeValue();       //初始化模拟量实时值表
            InitJyRealTimeTable();              //绝缘
            InitLlRealTimeTable();              //漏流
            InitCYRealTimeValue();              //残压
            InitRealTimeStatueTable();          //实时值
            //InitRealTimeAlarmValue();           //初始化实时报警表格
            c_LK.InitHostHardwarePlatform(ref HostHardwarePlatform);
            c_LK.InitLianSuoGaiFangCommandInfo(ref LianSuoGaiFangCommandInfo);
            c_LK.InitLianSuoGaiFangCommandRet(ref LianSuoGaiFangCommandRet);
            c_LK.InitLianSuoJieKouRouteInfo(ref LianSuoJieKouRouteInfo);
            c_LK.InitSectionEncodeInfo(ref SectionEncodeInfo);
            c_LK.InitSendToLianSuoInfo(ref SendToLianSuoInfo);
            c_LK.InitTemporaryLimitSpeedState(ref TemporaryLimitSpeedState);
            c_LK.InitTransponderEncodeInfo(ref TransponderEncodeInfo);
            c_LK.InitZhanJianBoundaryInfo(ref ZhanJianBoundaryInfo);
            c_LK.InitZhanJianGaiFangCommandInfo(ref ZhanJianGaiFangCommandInfo);
            c_LK.InitZhanJianGaiFangCommandRet(ref ZhanJianGaiFangCommandRet);
            c_LK.InitStatueInfo(ref Statue_Info);
            c_ReceiveData.NewStatueInfo+=new EventHandler(Event_NewStatueInfo);
            c_ReceiveData.NewLkInfo+=new EventHandler(Event_NewLkInfo);
            c_ReceiveData.NewCommandRet += new EventHandler(Event_NewCommandRet);
            c_ReceiveData.NewKglEvent += new EventHandler(Event_NewKglEvent);
            c_ReceiveData.NewAnalogEvent += new EventHandler(Event_NewAnalogEvent);
            c_NetData.NewLKEvent += new EventHandler(Event_NewLkInfo_Ter);
            C_MyPipe.PipeErrorEvent += new EventHandler(Eevent_PipeError);
        }
        /// <summary>
        /// 管道错误处理，需要清除数据.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        static private void Eevent_PipeError(object sender, EventArgs e)
        {
            //模拟量实时值：
            lock (ReceiveAnalogData)
            {
                foreach (byte b in ReceiveAnalogData.Keys)
                {
                    List<short> li = ReceiveAnalogData[b];
                    for (int i = 0; i < li.Count; i++)
                    {
                        li[i] = -1;
                    }
                }
            }
            DisposeAnalogRealTimeValue();
            //开关量
            for(int i = 0;i<ReceiveKGLData.Value.Count;i++)
            {
                ReceiveKGLData.Value[i] = 0;
            }
            DisposeKglRealTimeValue();
            //状态信息
            for(int i = 0;i<StatueTable.Rows.Count;i++)
            {
                StatueTable.Rows[i]["状态"] = "未知";
            }
            //列控硬件平台实时信息
            for(int i = 0;i<HostHardwarePlatform.Rows.Count;i++)
            {
                HostHardwarePlatform.Rows[i]["A机状态"] = "---";
                HostHardwarePlatform.Rows[i]["B机状态"] = "---";
            }
            //列控轨道区段状态信息
            for(int i = 0;i<Statue_Info.Tables.Count;i++)
            {
                for(int j = 0;j<Statue_Info.Tables[i].Rows.Count;j++)
                {
                    Statue_Info.Tables[i].Rows[j]["状态"] = "---";
                }
            }
        }

        /// <summary>
        /// 消息处理列控实时信息，终端使用。
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        static private void Event_NewLkInfo_Ter(object sender, EventArgs e)
        {
            List<byte> li = sender as List<byte>;
            int lkProtecol = li[0];
            
            if (lkProtecol == 0x01 || lkProtecol == 0x02)
            {
                c_LK.Fill_HostHardwarePlatform(ref HostHardwarePlatform, li);
            }
            else if (lkProtecol == 0x03)
            {
                c_LK.Fill_Protecol_0x10(ref LianSuoJieKouRouteInfo, li);
            }
            else if (lkProtecol == 0x04)
            {
                c_LK.Fill_Protecol_0x10(ref LianSuoGaiFangCommandInfo, li);
            }
            else if (lkProtecol == 0x05)
            {
                c_LK.Fill_Protecol_0x10(ref LianSuoGaiFangCommandRet, li);
            }
            else if (lkProtecol == 0x06)
            {
                c_LK.Fill_Protecol_0x10(ref ZhanJianGaiFangCommandInfo, li);
            }
            else if (lkProtecol == 0x07)
            {
                c_LK.Fill_Protecol_0x10(ref ZhanJianGaiFangCommandRet, li);
            }
            else if (lkProtecol == 0x08)
            {
                c_LK.Fill_Protecol_0x10(ref ZhanJianBoundaryInfo, li);
            }
            else if (lkProtecol == 0x09)
            {
                c_LK.Fill_Protecol_0x10(ref SendToLianSuoInfo, li);
            }
            else if (lkProtecol == 0x10)
            {
                c_LK.Fill_Protecol_0x10(ref TemporaryLimitSpeedState, li);
            }
            else if (lkProtecol == 0x11)
            {
                c_LK.Fill_Protecol_0x02(ref SectionEncodeInfo, li);
            }
            else if (lkProtecol == 0x12)
            {
                c_LK.Fill_Protecol_0x10(ref TransponderEncodeInfo, li);
            }
        }

        static private void DisposeRealTimeStatue(List<byte>li)
        {
            if (li.Count > 0) StatueTable.Rows.Clear();
            int m = 0;
            int Num = li[m] + (li[m + 1] << 8);
            m += 2;
            for (int i = 0; i < Num; i++)
            {
                int type = li[m++];
                int textLen = li[m++];
                string text = System.Text.Encoding.Default.GetString(li.ToArray(), m, textLen);
                m += textLen;
                int statue = li[m] + (li[m + 1] << 8);
                m += 2;
                DataRow dr = StatueTable.NewRow();
                string stype = "";
                if (type == 1) stype = "智能接口";
                else if (type == 2) stype = "CAN分机";
                else if (type == 3) stype = "采集单元";
                dr["类型"] = stype;
                dr["设备名称"] = text;
                string sstaue = "";
                if (statue == 0) sstaue = "异常";
                else if (statue == 1) sstaue = "正常";
                else sstaue = "无效";
                dr["状态"] = sstaue;
                StatueTable.Rows.Add(dr);
            }
        }

        static private void Event_NewStatueInfo(Object sender, EventArgs e)
        {
            try
            {
                List<byte> li = (List<byte>)sender;
                DisposeRealTimeStatue(li);
            }
            catch
            {
                Console.WriteLine("RevRTStatueIfor 异常");
            }

        }
        /// <summary>
        /// 检查发送给服务器的报警数据，如果超过3分钟没有回执，则重新发送
        /// </summary>
        

        static private void Event_NewAnalogEvent(object sender, EventArgs e)  //从队列中把模拟量数据加入到接收缓冲区中.
        {
            try
            {
                objRevAnalogType TmpRevData = sender as objRevAnalogType;

                byte Key = TmpRevData.AnalogType;
                if (ReceiveAnalogData.ContainsKey(Key))
                {
                    ReceiveAnalogData.Remove(Key);
                }
                ReceiveAnalogData.Add(Key, TmpRevData.ValueList);
            }
            catch
            {
                Console.WriteLine("RevAnalogQueue 异常");
            }
            DisposeAnalogRealTimeValue();     //把收到的实时值转换成显示用数据.
        }
        /// <summary>
        /// 把变化开关量填充到全体开关量中
        /// </summary>
        /// <param name="t"></param>
        static public void DisposeChangeKgl(objRevKGL t)
        {
            int j = 0;
            for (int i = 0; i < t.kglNum; i++)
            {
                int no = t.Value[j] + t.Value[j + 1];
                j += 2;
                byte s = (byte)(no>>15);
                no = no&0x7fff;
                int B = no / 8;     //字节数
                int b = no % 8;     //字节所在的位

                if (B < ReceiveKGLData.Value.Count)
                {
                    byte v = ReceiveKGLData.Value[B];
                    v = (byte)(v & (s << b));
                    v = (byte)(v | (s << b));
                    ReceiveKGLData.Value[B] = v;
                }
            }
        }

        static public void Event_NewKglEvent(object sender, EventArgs e)
        {
            objRevKGL t = sender as objRevKGL;

            if (t.AllFlag)
            {
                ReceiveKGLData = t; //类直接相等，是引用
            }
            else
            {
                ReceiveChangeKglData = t;   //变化开关量
                DisposeChangeKgl(t);
                c_NetCom.AutoSendkglChangeRealTimeData();   //发送实时变化开关量
            }
            DisposeKglRealTimeValue();
        }


        static private void Event_NewCommandRet(object sender, EventArgs e)
        {
            ReceiveCommandData.Clear();
            try
            {
                objRevCommandType obj = sender as objRevCommandType;
                ReceiveCommandData.Add(obj);
            }
            catch
            {
                Console.WriteLine("RevCommandRet 异常");
            }
            DisposeCommandRetValue();
        }

        static private void Event_NewLkInfo(object sender,EventArgs e)
        {
            ReceiveLkData.Clear();                
            objRevLkType obj = sender as objRevLkType;                    
            ReceiveLkData.Add(obj);
            DisposeLkRealTimeValue();
        }
        /// <summary>
        /// 初始化实时值列表，以设备表的结构初始化
        /// </summary>
        static private void InitMsgGatherRealTimeValue()
        {
            foreach(KeyValuePair<string,objMsgGatherStruct> li in c_Device.DeviceMsgGather)
            {
                string DevTypeName = li.Key;
                List<ObjRealTimeValue> tmpRealTimeValueList = new List<ObjRealTimeValue>();
                for (int i = 0; i < li.Value.DevList.Count; i++)
                {
                    ObjRealTimeValue tmpRealTimeValue = new ObjRealTimeValue();
                    tmpRealTimeValue.DevName = li.Value.DevList[i].DevName;
                    tmpRealTimeValueList.Add(tmpRealTimeValue);
                }
                if (RealTimeValue_Analog.ContainsKey(DevTypeName))
                { }
                else
                {
                    RealTimeValue_Analog.Add(DevTypeName, tmpRealTimeValueList);
                }
            }            
        }

        /// <summary>
        /// 初始化实时开关量表
        /// </summary>
        static private void InitKglRealTimeTable()
        {            
            for (int i = 0; i < c_Device.KGL_Config.Count; i++)
            {
                kglstruct kgl = new kglstruct();
                kgl.kglName = c_Device.KGL_Config[i].Name;
                kgl.fjNo = c_Device.KGL_Config[i].FeiJiNo.ToString();
                kgl.statue = "↓";
                kgl.type = c_Device.KGL_Config[i].SourceFlag;
                string s = ""; string ss = "";
                c_Device.GetKGLInMsgGather(i, ref s, ref ss);
                kgl.MsgName = s;
                kgl.DevName = ss;
                kgl.BHflag = "0";
                kglRealTimeList.Add(kgl);                
            }
        }

        static private void ThreadWaitJyRealTimeValue(object o)
        {
            int SleepCount = 10;
            while (true)
            {
                if (JyLlobject.Ready_JyNewstValue)
                {
                    foreach(string key in JyLlobject.Jy_NewstValueList.Keys)
                    {
                        //加入实时缓冲区
                        objTV tv = new objTV();
                        tv.utime = JyLlobject.Jy_NewstValueList[key].dValue.u_time;
                        tv.value = JyLlobject.Jy_NewstValueList[key].dValue.Dvalue;
                        objCodeDev cd = new objCodeDev();
                        cd.codetype = 0x80; //绝缘的模拟量类型
                        cd.dev_no = JyLlobject.Jy_NewstValueList[key].dev_no;   //模拟量序号

                        try
                        {
                            if (Monitor.TryEnter(JyLlCyRealTimeValue, 500))
                            {
                                if (!JyLlCyRealTimeValue.Keys.Contains(cd))
                                {
                                    JyLlCyRealTimeValue.Add(cd, tv);    //加入到实时值列表中
                                }
                                Monitor.Exit(JyLlCyRealTimeValue);
                            }
                        }
                        catch
                        {

                        }

                        //下面填充表格
                        DataRow dr = JyRealTimeTable.Rows.Find(key);
                        if (dr != null)
                        {
                            //dr.BeginEdit();
                            try
                            {
                                dr["测试值"] = JyLlobject.Jy_NewstValueList[key].dValue.Tvalue.Value.ToString();
                                dr["测试时间"] = JyLlobject.Jy_NewstValueList[key].time;
                            }
                            catch (Exception e) { }
                            //dr.EndEdit();                            
                        }
                        else
                        {
                            MessageInfo(null, new MessageInfoEventArgs("绝缘设备名称不匹配"));
                        }
                    }
                    //JyRealTimeTable.AcceptChanges();
                    break;
                }
                else if (JyLlobject.ErrorFlag != 0)
                {
                    //MessageBox.Show("绝缘最新值获取错误");
                    //MessageInfo(null, new MessageInfoEventArgs("绝缘最新值获取错误"));
                    break;
                }
                else
                {                    
                    Thread.Sleep(500);
                    SleepCount--;
                    if (SleepCount == 0)
                    {
                        MessageInfo(null, new MessageInfoEventArgs("绝缘最新值超时错误"));
                        break;
                    }
                }
            }
        }

        /// <summary>
        /// 初始化绝缘实时值表格，初始填充表格，并查询数据库
        /// </summary>
        static private void InitJyRealTimeTable()
        {
            string s = "电缆绝缘";
            JyRealTimeTable.Columns.Add("设备名称", typeof(string));
            JyRealTimeTable.Columns.Add("测试值", typeof(string));
            JyRealTimeTable.Columns.Add("测试时间", typeof(DateTime));
            JyRealTimeTable.PrimaryKey = new DataColumn[] { JyRealTimeTable.Columns["设备名称"] };      //设置键值
            foreach (string key in c_Device.DeviceMsgGather.Keys)
            {
                if (key==s)
                {
                    for (int i = 0; i < c_Device.DeviceMsgGather[key].DevList.Count; i++)
                    {
                        DataRow dr = JyRealTimeTable.NewRow();
                        dr["设备名称"] = c_Device.DeviceMsgGather[key].DevList[i].DevName;
                        dr["测试值"] = "未测试";
                        JyRealTimeTable.Rows.Add(dr);
                    }
                }
            }
            
            JyLlobject.ReadJyLlCyNewstValue(s);
            ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadWaitJyRealTimeValue), null);
        }
        /// <summary>
        /// 线程函数，等待查询数据库结束后，填充漏流的最新值表
        /// </summary>
        /// <param name="o"></param>
        static private void ThreadWaitLlRealTimeValue(object o)
        {
            int SleepCount = 10;
            while (true)
            {
                if (JyLlobject.Ready_LlNewstValue)
                {
                    foreach (string key in JyLlobject.Ll_NewstValueList.Keys)
                    {
                        objTV tv = new objTV();
                        tv.utime = JyLlobject.Ll_NewstValueList[key].dValue.u_time;
                        tv.value = JyLlobject.Ll_NewstValueList[key].dValue.Dvalue;
                        objCodeDev cd = new objCodeDev();
                        cd.codetype = 0x81; //漏流的模拟量类型
                        cd.dev_no = JyLlobject.Ll_NewstValueList[key].dev_no;   //模拟量序号
                        if (Monitor.TryEnter(JyLlCyRealTimeValue, 500))
                        {
                            if (JyLlCyRealTimeValue.Keys.Contains(cd))
                            { }
                            else
                            {
                                JyLlCyRealTimeValue.Add(cd, tv);    //加入到实时值列表中
                            }
                            Monitor.Exit(JyLlCyRealTimeValue);
                        }
                        //-----------------
                        DataRow dr = LlRealTimeTable.Rows.Find(key);
                        if (dr != null)
                        {
                            dr.BeginEdit();
                            dr["测试值"] = JyLlobject.Ll_NewstValueList[key].dValue.Tvalue.Value.ToString();
                            dr["测试时间"] = JyLlobject.Ll_NewstValueList[key].time;
                            dr.EndEdit();
                        }
                        else
                        {
                            MessageInfo(null, new MessageInfoEventArgs("漏流设备名称不匹配"));
                        }
                    }
                    //JyRealTimeTable.AcceptChanges();
                    break;
                }
                else if (JyLlobject.ErrorFlag != 0)
                {
                    //MessageBox.Show("绝缘最新值获取错误");
                    //MessageInfo(null, new MessageInfoEventArgs("漏流最新值获取错误"));
                    break;
                }
                else
                {
                    Thread.Sleep(500);
                    SleepCount--;
                    if (SleepCount == 0)
                    {
                        //MessageInfo(null, new MessageInfoEventArgs("漏流最新值超时错误"));
                        break;
                    }
                }
            }
        }
        /// <summary>
        /// 初始化漏流的最新值，构建表格，并查询数据库，填充表格
        /// </summary>
        static private void InitLlRealTimeTable()
        {
            string s = "电源漏流";
            LlRealTimeTable.Columns.Add("设备名称", typeof(string));
            LlRealTimeTable.Columns.Add("测试值", typeof(string));
            LlRealTimeTable.Columns.Add("测试时间", typeof(DateTime));
            LlRealTimeTable.PrimaryKey = new DataColumn[] { LlRealTimeTable.Columns["设备名称"] };
            foreach (string key in c_Device.DeviceMsgGather.Keys)
            {
                if (key.Contains(s))
                {
                    for (int i = 0; i < c_Device.DeviceMsgGather[key].DevList.Count; i++)
                    {
                        DataRow dr = LlRealTimeTable.NewRow();
                        dr["设备名称"] = c_Device.DeviceMsgGather[key].DevList[i].DevName;
                        dr["测试值"] = "未测试";
                        LlRealTimeTable.Rows.Add(dr);
                    }
                }
            }
            JyLlobject.ReadJyLlCyNewstValue(s);
            ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadWaitLlRealTimeValue), null);
        }

        static private void ThreadWaitCYRealTimeValue(object o)
        {
            int SleepCount = 10;
            while (true)
            {
                if (JyLlobject.Ready_CyNewstValue)
                {
                    foreach (string key in JyLlobject.Cy_NewstValueList.Keys)
                    {
                        objTV tv = new objTV();
                        tv.utime = JyLlobject.Cy_NewstValueList[key].dValue.u_time;
                        tv.value = JyLlobject.Cy_NewstValueList[key].dValue.Dvalue;
                        objCodeDev cd = new objCodeDev();
                        cd.codetype = 0x24; //分路残压的模拟量类型
                        cd.dev_no = JyLlobject.Cy_NewstValueList[key].dev_no;   //模拟量序号
                        if (Monitor.TryEnter(JyLlCyRealTimeValue, 500))
                        {
                            if (!JyLlCyRealTimeValue.Keys.Contains(cd))
                            {
                                JyLlCyRealTimeValue.Add(cd, tv);    //加入到实时值列表中
                            }
                            Monitor.Exit(JyLlCyRealTimeValue);
                        }

                        ////-----------------
                        //DataRow dr = CyRealTimeTable.Rows.Find(key);
                        //if (dr != null)
                        //{
                        //    dr.BeginEdit();
                        //    dr["测试值(mA)"] = JyLlobject.Cy_NewstValueList[key].dValue.Tvalue.Value.ToString();
                        //    dr["测试时间"] = JyLlobject.Cy_NewstValueList[key].time;
                        //    dr.EndEdit();
                        //}
                        //else
                        //{
                        //    MessageInfo(null, new MessageInfoEventArgs("漏流设备名称不匹配"));
                        //}
                    }                    
                    break;
                }
                else if (JyLlobject.ErrorFlag != 0)
                {
                    //MessageBox.Show("绝缘最新值获取错误");
                    MessageInfo(null, new MessageInfoEventArgs("残压最新值获取错误"));
                    break;
                }
                else
                {
                    Thread.Sleep(500);
                    SleepCount--;
                    if (SleepCount == 0)
                    {
                        MessageInfo(null, new MessageInfoEventArgs("残压最新值超时错误"));
                        break;
                    }
                }
            }
        }

        static private void InitCYRealTimeValue()
        {
            string s = "分路残压";            
            JyLlobject.ReadJyLlCyNewstValue(s);
            ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadWaitCYRealTimeValue), null);
        }

        static private void InitRealTimeStatueTable()
        {
            StatueTable.Columns.Add("类型",typeof(string));
            StatueTable.Columns.Add("设备名称", typeof(string));
            StatueTable.Columns.Add("状态", typeof(string));
        }

        /// <summary>
        /// 获取绝缘漏流残压的最新值
        /// </summary>
        /// <param name="type"></param>
        /// <param name="devno"></param>
        /// <returns></returns>
        static public objTV GetJyLlCyRealTimeValue(byte type, Int16 devno)
        {
            objCodeDev obj = new objCodeDev();
            obj.codetype = type;
            obj.dev_no = devno;
            if (JyLlCyRealTimeValue.Keys.Contains(obj))
            {
                return JyLlCyRealTimeValue[obj];
            }
            objTV o = new objTV();
            o.utime = 0;
            o.value = -1;
            return o;
        }

        /// <summary>
        /// 把模拟量的值转换成实际的值，依据部标协议.
        /// </summary>
        /// <param name="AnalogType"></param>
        /// <param name="AnalogNo"></param>
        /// <param name="Value"></param>
        /// <returns></returns>
        static public ObjValue ConvertAnalogValue(string AnalogType, Int16 Value)
        {
            ObjValue retValue = new ObjValue();
            retValue.DecimalNum = 0;
            retValue.Value = -1;
            retValue.ValueType = "";
            Int16 TmpValue = Value;
            int flag = (TmpValue & 0x8000) >> 15;
            int dic = (TmpValue & 0x6000) >> 13;
            TmpValue = (short)(TmpValue & 0x1fff);
            float tmp = (float)TmpValue;

            if (AnalogType.Contains("载频") || AnalogType.Contains("上边频") || AnalogType.Contains("下边频") || AnalogType.Contains("ZPW-2000A接口信息") || AnalogType.Contains("轨道编码"))
            {
                tmp = tmp * 10f;
                if (tmp > 81920) tmp = -1;      //超过81920，则至为无效值
                retValue.DecimalNum = 0;
                retValue.Value = tmp;
                retValue.ValueType = "";
                return retValue;
            }
            else
            {
                //处理值和精度f
                if (dic == 1) tmp = tmp / 100f;
                else if (dic == 2) tmp = tmp / 10f;
                else if (dic == 3) tmp = tmp * 10f;
                if (tmp >= 0 && tmp <= 81.91)
                {
                    retValue.Value = tmp;
                    retValue.DecimalNum = 2;
                }
                else if (tmp >= 81.92 && tmp <= 81.94)
                {
                    tmp = 81.9f;
                    retValue.Value = tmp;
                    retValue.DecimalNum = 1;
                }
                else if (tmp >= 81.95 && tmp <= 81.99)
                {
                    tmp = 82.0f;
                    retValue.Value = tmp;
                    retValue.DecimalNum = 1;
                }
                else if (tmp >= 82.0 && tmp <= 819.1)
                {
                    retValue.Value = tmp;
                    retValue.DecimalNum = 1;
                }
                else if (tmp >= 819.2 && tmp <= 819.4)
                {
                    tmp = 819.0f;
                    retValue.Value = tmp;
                    retValue.DecimalNum = 1;
                }
                else if (tmp >= 819.5 && tmp <= 819.9)
                {
                    tmp = 820;
                    retValue.Value = tmp;
                    retValue.DecimalNum = 0;
                }
                else if (tmp >= 820 && tmp <= 81920)
                {
                    retValue.Value = tmp;
                    retValue.DecimalNum = 0;
                }
                else if (tmp > 81920)
                {
                    tmp = -1;
                    retValue.Value = tmp;
                    retValue.DecimalNum = 0;
                }

                //处理标志位
                if (AnalogType.Contains("轨道电压") || AnalogType.Contains("轨道相位角") ||
                    AnalogType.Contains("主轨轨入电压") || AnalogType.Contains("轨出1电压") || AnalogType.Contains("轨出2电压") || AnalogType.Contains("小轨轨入电压"))
                {
                    if (flag == 1) retValue.ValueType = "调整";
                    else retValue.ValueType = "分路";
                }
                else if (AnalogType.Contains("电码化发送电流"))
                {
                    if (flag == 1) retValue.ValueType = "空闲";
                    else retValue.ValueType = "占用";
                }
                else if (AnalogType.Contains("道岔表示电压"))
                {
                    if (flag == 1) retValue.ValueType = "有表示";
                    else retValue.ValueType = "无表示";
                }
                else if (AnalogType.Contains("半自动闭塞") || AnalogType.Contains("站联电压"))
                {
                    if (flag == 0)
                    {
                        retValue.ValueType = "反向";
                        retValue.Value = 0f - retValue.Value;   //数值取反
                    }
                    else retValue.ValueType = "正向";
                }
                else if (AnalogType.Contains("环境模拟量") || AnalogType.Contains("高压不对称"))
                {
                    if (flag == 0)
                    {
                        retValue.ValueType = "";
                        retValue.Value = 0f - retValue.Value;   //数值取反
                    }
                }
            }
            return retValue;    
        }

        /// <summary>
        /// 根据模拟量类型和序号获得模拟量的实时值，转换过后的值
        /// </summary>
        /// <param name="AnalogType"></param>
        /// <param name="AnalogNo"></param>
        /// <returns></returns>
        static public ObjValue GetRealTimeAnalogValue(byte AnalogType, int AnalogNo)
        {
            ObjValue retValue = new ObjValue();
            retValue.ValueType = "";
            retValue.DecimalNum = 0;
            retValue.Value = -1;
            if (ReceiveAnalogData.ContainsKey(AnalogType))
            {
                if (AnalogNo >= 0 && AnalogNo < ReceiveAnalogData[AnalogType].Count)
                {
                    Int16 TmpValue = ReceiveAnalogData[AnalogType][AnalogNo];   //取模拟量值
                    if ((int)TmpValue == -1)     //0xffff,直接返回无效
                    {
                        retValue.DecimalNum = 0;
                        retValue.Value = -1;
                        retValue.ValueType = "";                        
                        return retValue;
                    }
                    string s = c_Device.GetAnalogTypeName((AnalogCodeType)AnalogType);
                    retValue = ConvertAnalogValue(s, TmpValue);
                }
            }

            else
            {
                int a = 10;
            }

            return retValue;
        }

        static public Int16 GetRealTimeAnalogDValue(byte Type, int no)
        {
            if (ReceiveAnalogData.ContainsKey(Type))
            {
                if (no >= 0 && no < ReceiveAnalogData[Type].Count)
                {
                    return ReceiveAnalogData[Type][no];
                }
            }
            return -1;
        }
        /// <summary>
        /// 根据设备类型名，设备名，设备属性，获得该属性的实时值
        /// </summary>
        /// <param name="DevTypeName"></param>
        /// <param name="DevName"></param>
        /// <param name="Attri"></param>
        /// <returns></returns>
        static public ObjValue GetRealTimeAnalogValue(string DevTypeName, string DevName, string Attri)
        {
            AnalogObj t = c_Device.GetAnalogDevNo(DevTypeName, DevName, Attri);
            string s = c_Device.GetAnalogTypeName(t.type);
            ObjValue v = GetRealTimeAnalogValue((byte)t.type, t.devNo);
            return v;
        }

        static public NowObjValue GetRealTimeAnalogValue_Check(string DevTypeName, string DevName, string Attri)
        {
            ObjValue t = GetRealTimeAnalogValue(DevTypeName, DevName, Attri);
            objSingleAnalogStruct a = c_Device.GetSingleAnalogConfig(DevTypeName, DevName, Attri);
            NowObjValue n = new NowObjValue();
            n.value = t;
            if (t.Value > a.UpperThreshold) n.CXBZ = "上限";
            else if (t.Value < a.LowerThreshold) n.CXBZ = "下限";
            else n.CXBZ = "";
            return n;
        }

        /// <summary>
        /// 根据开关量序号获得开关量的实时值
        /// </summary>
        /// <param name="No"></param>
        /// <returns></returns>
        static public int GetRealTimeKGLValue(int No)
        {
            if (No >= 0 && No < 2000 * 8)
            {
                int B = No / 8;
                int b = No % 8;
                if (B < ReceiveKGLData.Value.Count)
                {
                    byte t = ReceiveKGLData.Value[B];
                    return (t >> b) & 0x01;
                }
            }
            return -1;
        }

        static public int GetRealTimeKGLValue(string DevTypeName, string DevName, string attriName)
        {
            AnalogObj t = c_Device.GetAnalogDevNo(DevTypeName, DevName, attriName);
            if (t.type == AnalogCodeType.None && t.devNo != -1)
            {
                return GetRealTimeKGLValue(t.devNo);
            }
            return -1;
        }

        /// <summary>
        /// 刷新模拟量实时值表，依据MSGgather配置的，依据设备填充设备属性的值。也就是各种设备类型的实时值。
        /// </summary>
        static public void DisposeAnalogRealTimeValue()    //刷新模拟量实时值
        {
            if (Monitor.TryEnter(RealTimeValue_Analog, 500))
            {
                RealTimeValue_Analog.Clear();
                if (RealTimeValue_Analog.Count > 0)
                {
                    Console.WriteLine("模拟量实时值缓冲区错误");
                }
                foreach (KeyValuePair<string, objMsgGatherStruct> li in c_Device.DeviceMsgGather)
                {
                    string AnlogTypeName = li.Key;
                    List<ObjRealTimeValue> tmpRealTimeValueList = new List<ObjRealTimeValue>();
                    for (int i = 0; i < li.Value.DevList.Count; i++)    //一种模拟量类型所有的设备
                    {
                        string TmpDevName = li.Value.DevList[i].DevName;
                        ObjRealTimeValue tmpRealTimeValue = new ObjRealTimeValue();
                        tmpRealTimeValue.DevName = TmpDevName;
                        for (int j = 0; j < li.Value.DevList[i].AnalogSet.Count; j++)       //一个设备所有的模拟量集合
                        {
                            int tmpAnalogNo = li.Value.DevList[i].AnalogSet[j];
                            AnalogCodeType tmpAnalogType = li.Value.ArrtiList[j].AnalogType;
                            if (tmpAnalogType == AnalogCodeType.None)   //开关量
                            {
                                int kglv = GetRealTimeKGLValue(tmpAnalogNo);
                                ObjValue kk = new ObjValue();
                                kk.DecimalNum = 0;
                                kk.Value = kglv;
                                kk.ValueType = "开关量";
                                tmpRealTimeValue.DevValue.Add(kk);
                            }
                            else
                            {
                                string tmp = c_Device.GetAnalogTypeName(tmpAnalogType);
                                ObjValue tmpValue = GetRealTimeAnalogValue((byte)tmpAnalogType, tmpAnalogNo);       //从实时值缓冲区获得该模拟量的实时数据
                                tmpRealTimeValue.DevValue.Add(tmpValue);
                                if (tmpValue.Value == -1 && tmpAnalogNo != -1)
                                {
                                    int a = 1;
                                }
                            }
                        }
                        tmpRealTimeValueList.Add(tmpRealTimeValue);
                    }
                    if (RealTimeValue_Analog.ContainsKey(AnlogTypeName))
                    {
                        Console.WriteLine(string.Format("模拟量实时值，{0},键重复", AnlogTypeName));
                    }
                    else
                    {
                        try
                        {
                            RealTimeValue_Analog.Add(AnlogTypeName, tmpRealTimeValueList);
                        }
                        catch
                        { }
                    }
                }
                Monitor.Exit(RealTimeValue_Analog);
            }
        }

        /// <summary>
        /// 刷星开关量实时值表，依据开关量表配置，填充开关量实时表格的数据
        /// </summary>
        static private void DisposeKglRealTimeValue()
        {
            //for (int i = 0; i < KglRealTimeTable.Rows.Count; i++)
            //{              
            //    //DataRow dr = KglRealTimeTable.Rows[i];
            //    int m = GetRealTimeKGLValue(i);
            //    string s = "";
            //    if (m == -1) s = "未知";
            //    else if (m == 1) s = "↑";
            //    else if (m == 0) s = "  ↓";
            //    if (s != KglRealTimeTable.Rows[i]["状态"].ToString())
            //    {
            //        KglRealTimeTable.Rows[i]["状态"] = s;
            //        KglRealTimeTable.Rows[i]["变化标志"] = "1";
            //    }
            //    else
            //    {
            //        if(KglRealTimeTable.Rows[i]["变化标志"].ToString() == "1")
            //            KglRealTimeTable.Rows[i]["变化标志"] = "0";
            //    }
            //}
            for(int i = 0;i<kglRealTimeList.Count;i++)
            {                
                int m = GetRealTimeKGLValue(i);
                string  s= "";
                if (m == -1) s= "未知";
                else if (m == 1) s = "↑";
                else if (m == 0) s = "↓";
                if(kglRealTimeList[i].statue != s)
                {
                    kglRealTimeList[i].statue = s;
                    kglRealTimeList[i].BHflag = "1";
                }
                else kglRealTimeList[i].BHflag = "0";
            }
        }

        /// <summary>
        /// 处理逻辑处理层发送过来的命令回执信息
        /// </summary>
        static private void DisposeCommandRetValue()
        {
            foreach (objRevCommandType obj in ReceiveCommandData)
            {
                if (obj.type == 1)   //配置修改返回
                {
                    int Num = obj.value[0]+(obj.value[1]<<8);
                    int m = 2;
                    for (int i = 0; i < Num; i++)
                    {
                        int okFlag = obj.value[m++];  //成功标记
                        int analogType = obj.value[m++];
                        int analogNo = obj.value[m] + (obj.value[m+1] << 8);
                        m += 2;
                        //-----------修改前上限-------
                        int upLen = obj.value[m++];
                        string upstring = System.Text.Encoding.Default.GetString(obj.value.ToArray(), m, upLen);
                        m += upLen;
                        float f_up = float.Parse(upstring);
                        //-----------修改前下限--------
                        int dnLen = obj.value[m++];
                        string dnstring = System.Text.Encoding.Default.GetString(obj.value.ToArray(), m, dnLen);
                        m += dnLen;
                        float f_dn = float.Parse(dnstring);
                        //------------修改前分路上限-----
                        int fupLen = obj.value[m++];
                        string fupstring = System.Text.Encoding.Default.GetString(obj.value.ToArray(), m, fupLen);
                        m += fupLen;
                        float f_fup = float.Parse(fupstring);                        
                        //------------修改后上限----------
                        int bupLen = obj.value[m++];
                        string bupstring = System.Text.Encoding.Default.GetString(obj.value.ToArray(), m, bupLen);
                        m += bupLen;
                        float b_up = float.Parse(bupstring);                        
                        //------------修改后下限----------
                        int bdnLen = obj.value[m++];
                        string bdnstring = System.Text.Encoding.Default.GetString(obj.value.ToArray(), m, bdnLen);
                        m += bdnLen;
                        float b_dn = float.Parse(dnstring);                        
                        //------------修改后分路-----------
                        int bfupLen = obj.value[m++];
                        string bfupstring = System.Text.Encoding.Default.GetString(obj.value.ToArray(), m, bfupLen);
                        m += bfupLen;
                        float b_fup = float.Parse(fupstring);                        
                        //---------------------------------
                        if (okFlag == 0)    //修改配置失败
                        {
                            string typeName = c_Device.GetAnalogTypeName((AnalogCodeType)analogType);
                            MessageBox.Show(string.Format("配置修改失败,{0}_类型，序号_{1}", typeName, analogNo));
                        }
                        else
                        {
                            //修改内存中的值.
                            if (c_Device.IsValidAnalogType(analogType))
                            {
                                string keyString = c_Device.GetAnalogTypeName((AnalogCodeType)analogType);
                                if (c_Device.GD_AnalogConfig.ContainsKey(keyString))
                                {
                                    if (analogNo >= 0 && analogNo < c_Device.GD_AnalogConfig[keyString].AnalogList.Count)
                                    {
                                        c_Device.GD_AnalogConfig[keyString].AnalogList[analogNo].UpperThreshold = b_up;
                                        c_Device.GD_AnalogConfig[keyString].AnalogList[analogNo].LowerThreshold = b_dn;
                                        c_Device.GD_AnalogConfig[keyString].AnalogList[analogNo].FLUpperThreshold = b_fup;
                                    }
                                    else MessageInfo(null, new MessageInfoEventArgs("修改配置,序号越界"));
                                }
                                else if (c_Device.DC_AnalogConfig.ContainsKey(keyString))
                                {
                                    if (analogNo >= 0 && analogNo < c_Device.DC_AnalogConfig[keyString].AnalogList.Count)
                                    {
                                        c_Device.DC_AnalogConfig[keyString].AnalogList[analogNo].UpperThreshold = b_up;
                                        c_Device.DC_AnalogConfig[keyString].AnalogList[analogNo].LowerThreshold = b_dn;
                                        c_Device.DC_AnalogConfig[keyString].AnalogList[analogNo].FLUpperThreshold = b_fup;
                                    }
                                    else MessageInfo(null, new MessageInfoEventArgs("修改配置,序号越界"));
                                }
                                else if (c_Device.JC_AnalogConfig.ContainsKey(keyString))
                                {
                                    if (analogNo >= 0 && analogNo < c_Device.JC_AnalogConfig[keyString].AnalogList.Count)
                                    {
                                        c_Device.JC_AnalogConfig[keyString].AnalogList[analogNo].UpperThreshold = b_up;
                                        c_Device.JC_AnalogConfig[keyString].AnalogList[analogNo].LowerThreshold = b_dn;
                                        c_Device.JC_AnalogConfig[keyString].AnalogList[analogNo].FLUpperThreshold = b_fup;
                                    }
                                    else MessageInfo(null, new MessageInfoEventArgs("修改配置,序号越界"));
                                }
                                else if (c_Device.ZH_AnalogConfig.ContainsKey(keyString))
                                {
                                    if (analogNo >= 0 && analogNo < c_Device.ZH_AnalogConfig[keyString].AnalogList.Count)
                                    {
                                        c_Device.ZH_AnalogConfig[keyString].AnalogList[analogNo].UpperThreshold = b_up;
                                        c_Device.ZH_AnalogConfig[keyString].AnalogList[analogNo].LowerThreshold = b_dn;
                                        c_Device.ZH_AnalogConfig[keyString].AnalogList[analogNo].FLUpperThreshold = b_fup;
                                    }
                                    else MessageInfo(null, new MessageInfoEventArgs("修改配置,序号越界"));
                                }
                                else if (c_Device.YP_AnalogConfig.ContainsKey(keyString))
                                {
                                    if (analogNo >= 0 && analogNo < c_Device.YP_AnalogConfig[keyString].AnalogList.Count)
                                    {
                                        c_Device.YP_AnalogConfig[keyString].AnalogList[analogNo].UpperThreshold = b_up;
                                        c_Device.YP_AnalogConfig[keyString].AnalogList[analogNo].LowerThreshold = b_dn;
                                        c_Device.YP_AnalogConfig[keyString].AnalogList[analogNo].FLUpperThreshold = b_fup;
                                    }
                                    else MessageInfo(null, new MessageInfoEventArgs("修改配置,序号越界"));
                                }
                                else
                                {
                                    MessageInfo(null, new MessageInfoEventArgs("修改配置，模拟量类型错误"));
                                }
                            }
                            //上传服务器
                        }
                    }
                }
                else if (obj.type == 2) //绝缘测试返回值
                {
                    int No = obj.value[0]+(obj.value[1]<<8);

                    //绝缘发送过来的值是转换成word的值。
                    int dValue = obj.value[2] + (obj.value[3] << 8);
                    
                    //需要更新实时内存中的值
                    objCodeDev cd = new objCodeDev();
                    cd.codetype = 0x80;
                    cd.dev_no = (Int16)No;
                    objTV tv = new objTV();
                    tv.value = (short)dValue;
                    tv.utime = MySql.DateTimeToTime_t(DateTime.Now);
                    if (JyLlCyRealTimeValue.Keys.Contains(cd))
                    {
                        JyLlCyRealTimeValue[cd] = tv;
                    }
                    else
                    {
                        JyLlCyRealTimeValue.Add(cd, tv);
                    }
                    
                    ObjValue t = ConvertAnalogValue("绝缘", (Int16)dValue);
                    float value = t.Value;

                    if (No >= 0 && No < JyRealTimeTable.Rows.Count)
                    {
                        DataRow dr = JyRealTimeTable.Rows[No];
                        dr.BeginEdit();
                        dr["测试值"] = value.ToString();
                        dr["测试时间"] = MySql.Time_tToDateTime(tv.utime).ToString();
                        dr.EndEdit();
                    }
                    else MessageInfo(null, new MessageInfoEventArgs("绝缘测试，返回序号错误"));
                }
                else if (obj.type == 3) //漏流测试返回值
                {
                    int No = obj.value[0] + (obj.value[1] << 8);

                    int dValue = obj.value[2] + (obj.value[3] << 8);
                    
                    //需要更新实时内存中的值
                    objCodeDev cd = new objCodeDev();
                    cd.codetype = 0x81;
                    cd.dev_no = (Int16)No;
                    objTV tv = new objTV();
                    tv.value = (short)dValue;
                    tv.utime = MySql.DateTimeToTime_t(DateTime.Now);
                    if (JyLlCyRealTimeValue.Keys.Contains(cd))
                    {
                        JyLlCyRealTimeValue[cd] = tv;
                    }
                    else
                    {
                        JyLlCyRealTimeValue.Add(cd, tv);
                    }
                    
                    ObjValue t = ConvertAnalogValue("漏流", (Int16)dValue);
                    float value = t.Value;
                             

                    if (No >= 0 && No < LlRealTimeTable.Rows.Count)
                    {
                        DataRow dr = LlRealTimeTable.Rows[No];
                        dr.BeginEdit();
                        dr["测试值"] = value.ToString();                        
                        dr["测试时间"] = MySql.Time_tToDateTime(tv.utime).ToString();
                        dr.EndEdit();                        
                    }
                    else MessageInfo(null, new MessageInfoEventArgs("漏流测试，返回序号错误"));
                }
                else if (obj.type == 4) //高压不对称返回值
                {
                    int No = obj.value[0] + (obj.value[1] << 8);
                    ObjGybdcType gyobj = new ObjGybdcType();
                    gyobj.objset = c_Device.GetGybdcqx_AnalogConfigSet(No);
                    int m = 2;
                    gyobj.start1 = obj.value[m] + (obj.value[m + 1] << 8) + (obj.value[m + 2] << 16) + (obj.value[m + 3] << 24);
                    m += 4;
                    gyobj.dotnum1 = (short)(obj.value[m] + (obj.value[m + 1] << 8));
                    m += 2;
                    for (int i = 0; i < gyobj.dotnum1; i++)
                    {
                        ObjRCurValue or = new ObjRCurValue();
                        or.wValue = (short)(obj.value[m] + (obj.value[m + 1] << 8));
                        or.tValue = ConvertAnalogValue("高压不对称", or.wValue);
                        gyobj.qx1.Add(or);
                    }

                    gyobj.start2 = obj.value[m] + (obj.value[m + 1] << 8) + (obj.value[m + 2] << 16) + (obj.value[m + 3] << 24);
                    m += 4;
                    gyobj.dotnum2 = (short)(obj.value[m] + (obj.value[m + 1] << 8));
                    m += 2;
                    for (int i = 0; i < gyobj.dotnum2; i++)
                    {
                        ObjRCurValue or = new ObjRCurValue();
                        or.wValue = (short)(obj.value[m] + (obj.value[m + 1] << 8));
                        or.tValue = ConvertAnalogValue("高压不对称", or.wValue);
                        gyobj.qx2.Add(or);
                    }

                    gyobj.start3 = obj.value[m] + (obj.value[m + 1] << 8) + (obj.value[m + 2] << 16) + (obj.value[m + 3] << 24);
                    m += 4;
                    gyobj.dotnum3 = (short)(obj.value[m] + (obj.value[m + 1] << 8));
                    m += 2;
                    for (int i = 0; i < gyobj.dotnum3; i++)
                    {
                        ObjRCurValue or = new ObjRCurValue();
                        or.wValue = (short)(obj.value[m] + (obj.value[m + 1] << 8));
                        or.tValue = ConvertAnalogValue("高压不对称", or.wValue);
                        gyobj.qx3.Add(or);
                    }
                    RevRealTimeGYBDCqx.Clear();
                    string key = c_Device.GetGybdcDyDevName(No);
                    RevRealTimeGYBDCqx.Add(key, gyobj);
                }
            }
        }
        /// <summary>
        /// 处理列控发送过来的信息，填充表格
        /// </summary>
        static private void DisposeLkRealTimeValue()
        {
            foreach (objRevLkType key in ReceiveLkData)
            {
                if(key.LkTypeName == "硬件平台A")
                {
                    c_LK.ParseProtecol_HostHardwarePlatform(ref HostHardwarePlatform, key.ValueList.ToArray());
                }
                else if (key.LkTypeName == "硬件平台B")
                {
                    c_LK.ParseProtecol_HostHardwarePlatform(ref HostHardwarePlatform, key.ValueList.ToArray());
                }
                else if (key.LkTypeName == "联锁接口进路信息")
                {
                   c_LK.ParseProtecol_LianSuoJieKouRouteInfo(ref LianSuoJieKouRouteInfo, key.ValueList.ToArray());
                }
                else if(key.LkTypeName == "联锁改方命令信息")
                {
                    c_LK.ParseProtecol_LianSuoGaiFangCommandInfo(ref LianSuoGaiFangCommandInfo, key.ValueList.ToArray());
                }
                else if(key.LkTypeName == "联锁改方回执信息")
                {
                    c_LK.ParseProtecol_LianSuoGaiFangCommandRet(ref LianSuoGaiFangCommandRet, key.ValueList.ToArray());
                }
                else if(key.LkTypeName == "站间改方命令")
                {
                    c_LK.ParseProtecol_ZhanJianGaiFangCommandInfo(ref ZhanJianGaiFangCommandInfo, key.ValueList.ToArray());
                }
                else if(key.LkTypeName == "站间改方回执")
                {
                    c_LK.ParseProtecol_ZhanJianGaiFangCommandRet(ref ZhanJianGaiFangCommandRet, key.ValueList.ToArray());
                }
                else if(key.LkTypeName == "站间边界信息")
                {
                    c_LK.ParseProtecol_ZhanJianBoundaryInfo(ref ZhanJianBoundaryInfo, key.ValueList.ToArray());
                }
                else if(key.LkTypeName == "临时限速状态")
                {
                    c_LK.ParseProtecol_TemporaryLimitSpeedState(ref TemporaryLimitSpeedState, key.ValueList.ToArray());
                }
                else if(key.LkTypeName == "轨道区段编码信息")
                {
                    c_LK.ParseProtecol_SectionEncodeInfo(ref SectionEncodeInfo, key.ValueList.ToArray());
                }
                else if(key.LkTypeName == "状态全体信息")
                {
                    c_LK.ParaseProtecol_AllStatueInfo(ref Statue_Info, key.ValueList.ToArray());
                }
                else if(key.LkTypeName == "应答器报文编码信息")
                {
                    c_LK.ParaseProtecol_TransponderEncodeInfo(ref TransponderEncodeInfo, key.ValueList.ToArray());
                }
                else if (key.LkTypeName == "无配线站方向口信息")
                {
                    c_LK.ParseProtecol_SendToLianSuoInfo(ref SendToLianSuoInfo, key.ValueList.ToArray());
                }                
            }
        }        
    }
}
